package stu.day33_day38.day33;

import java.util.Scanner;

public class hw2 {



    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        char[][] ch = new char[n][m];
        for(int i =0;i<n;i++){
            String str = sc.nextLine();
            for(int j=0;j<m;j++){
                ch[i][j] = str.charAt(j);
            }
        }
        int num = 0;
        for(int i =0;i<n;i++){
            for(int j=0;j<m;j++){
                if(ch[i][j]!='#'){
                    int x = dfs(i,j,n,m,ch);
                    num += x<k?1:0;


                }
            }
        }


        System.out.println(num);


    }


    public static int dfs(int i,int j,int n,int m,char[][] ch){
        if(i>=0&&i<n&&j>=0&&j<m){
            if(ch[i][j]=='#'){
                return 0;
            }else {
                int num = ch[i][j]=='E'?1:0;
                ch[i][j]='#';
                return num+dfs(i+1,j,n,m,ch)+dfs(i-1,j,n,m,ch)+dfs(i,j+1,n,m,ch)+dfs(i,j-1,n,m,ch);
            }
        }
        return 0;
    }





}
